Imports ToDoList.Navigation
Imports ToDoList.Usecases

Public Class TaskDetailsForm
  Implements IEditTaskDetailsNavigation

  Private mUsecase As EditTaskDetailsUsecase
  Private mEditedTask As Model.Task

  ''' <summary>
  ''' application container should inject my usecase here
  ''' </summary>
  Sub Usecases(ByVal editTaskDetails As EditTaskDetailsUsecase)
    mUsecase = editTaskDetails
  End Sub

  ''' <summary>
  ''' Show this form with details of the given task. Other tasks
  ''' are needed to establish a dependency between two tasks
  ''' </summary>
  ''' <remarks></remarks>
  Public Sub ShowTaskDetails(ByVal task As Model.Task) Implements Navigation.IEditTaskDetailsNavigation.ShowTaskDetails
    'fill controls with the task contents
    txtTitle.Text = task.Title
    txtComments.Text = task.Comments

    tbCompleted.Value = task.PercentDone
    tbPriority.Value = task.Priority

    'keep to preserve other properties
    mEditedTask = task

    dtpDue.Value = mEditedTask.GetDueDate()

    'show this form
    Me.ShowDialog()
  End Sub

  ''' <summary>
  ''' handles ok click
  ''' </summary>
  Private Sub mnuOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOK.Click
    'set properties in editedtask
    mEditedTask.Title = txtTitle.Text
    mEditedTask.Comments = txtComments.Text

    mEditedTask.PercentDone = tbCompleted.Value
    mEditedTask.Priority = tbPriority.Value

    mEditedTask.SetDueDate(dtpDue.Value)

    'tell usecase
    mUsecase.EditingFinished(mEditedTask)

    'close this form
    Close()
  End Sub

  ''' <summary>
  ''' handle cnacell click
  ''' </summary>
  Private Sub mnuCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCancel.Click
    'tell usecae
    mUsecase.EditingCancelled()

    'close this form
    Close()
  End Sub

End Class